package com.hxkcloud.patient.popwindow;


import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.TextView;

import com.hxkcloud.patient.R;

/**
 * @author cys
 *         <p>
 *         打开popwindow
 */
public class MyPopuWindow {
    private static MyBasePopuWindow basPopuWindow;

    public static void dismiss() {
        if (basPopuWindow != null && basPopuWindow.isShowing()) {
            basPopuWindow.dismiss();
        }
    }

    public static boolean isShowing() {
        if (basPopuWindow != null) {
            if (basPopuWindow.isShowing()) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    /**
     * 相册选择
     * @param context
     * @param resourseId
     * @param onClickListener
     */
    public static void drugAction(final Activity context, int resourseId, View.OnClickListener onClickListener) {
        View mMenuView;
        TextView tv_addDrugRecord,tv_addStopDrugRecord;

        basPopuWindow = new MyBasePopuWindow(context, null,
                R.layout.popup_select_drug_action, true);
        basPopuWindow.setAnimationStyle(R.style.popupwindow_anim_alpha);
//      basPopuWindow.setAnimationStyle(R.style.AnimTranslate);
        // 显示窗口
        ColorDrawable dw = new ColorDrawable(0x4C000000); // 0xb0000000
        // 设置SelectPicPopupWindow弹出窗体的背景
        basPopuWindow.setBackgroundDrawable(dw);
		basPopuWindow.showAsDropDown(context.findViewById(resourseId));
//        basPopuWindow.showAtLocation(context.findViewById(resourseId),
//                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); // 设置layout在PopupWindow中显示的位置
        mMenuView = basPopuWindow.getmMenuView();

        tv_addDrugRecord = (TextView) mMenuView.findViewById(R.id.tv_addDrugRecord);
        tv_addStopDrugRecord = (TextView) mMenuView.findViewById(R.id.tv_addStopDrugRecord);

        tv_addDrugRecord.setOnClickListener(onClickListener);
        tv_addStopDrugRecord.setOnClickListener(onClickListener);
    }
}